package com.cqyanyu.yanyu.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.provider.Settings;

/**
 * 项目名称：Europapa
 * 类描述：网络工具类
 * 创建人：cheng
 * 创建时间：2016/1/20 11:08
 * 修改人：cheng
 * 修改时间：2016/1/20 11:08
 * 修改备注：
 */
public class XNetworkUtil {
    static AlertDialog alertDialog;

    public static void setNetworkMethod(final Context context) {
        setNetworkMethod(context, false);
    }

    //判断网络去设置网络
    public static void setNetworkMethod(final Context context, final boolean onNetworkfinish) {
        if (alertDialog != null && alertDialog.isShowing()) {
            return;
        }
        if (!XAppUtil.isNetworkAvailable(context)) {
            //提示对话框
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            alertDialog = builder.setTitle("网络设置提示").setMessage("网络连接不可用,是否进行设置?").setPositiveButton("设置", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent(Settings.ACTION_SETTINGS);
                    context.startActivity(intent);
                }
            }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    dialog.dismiss();
                    if (onNetworkfinish) {
                        if (context instanceof Activity) {
                            ((Activity) context).finish();
                        }
                    }
                }
            }).show();
        }
    }
}
